package cn.itcast.mapper;

import cn.itcast.pojo.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Mapper
public interface EmpMapper extends BaseMapper<Emp> {
    /*@Select("select emp.*,dept.name deptName from emp left outer join dept on emp.dept_id = dept.id limit #{start},#{pageSize}")
    //List<Emp> findByConditionAndPage(String name, Integer gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end, Integer page, Integer pageSize);
    List<Emp> findByConditionAndPage(@Param("start") Integer start, @Param("pageSize") Integer pageSize);
    @Select("select count(*) from emp")
    int findTotalCount();*/
    List<Emp> findByConditionAndPage(
            @Param("name") String name,
            @Param("gender")  Integer gender,
            @Param("begin") LocalDate begin,
            @Param("end") LocalDate end
    );

    @Insert("insert into emp values(null,#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    int add(Emp emp);

    Emp findById(int id);

    //void update(Emp emp);

    void deleteByIds(@Param("ids") List<Integer> ids);

    List<Emp> findByIds(@Param("ids") List<Integer> ids);

    List<EmpGender> empGenderData();

    List<CountEmpByJob> empJobData();

    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp login(@Param("username") String username,@Param("password")String password);

    @Select("select * from emp")
    List<Emp> findAllEmp();

    void updateSalaryByIds(@Param("ew") LambdaQueryWrapper<Emp> wrapper, @Param("amount") int amount);

    @Select("select image from emp")
    Set<String> findAllEmpImage();
}
